package com.sg.business.taskforms.projectchange;

import org.eclipse.core.runtime.IProgressMonitor;

import com.mobnut.commons.util.Utils;
import com.sg.business.model.TaskForm;
import com.sg.business.model.Work;
import com.sg.widgets.part.editor.IDataObjectDialogCallback;
import com.sg.widgets.part.editor.PrimaryObjectEditorInput;

public class ProjectChangeConfirmSaveHandler implements
		IDataObjectDialogCallback {

	public ProjectChangeConfirmSaveHandler() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean okPressed() {
		return false;
	}

	@Override
	public void cancelPressed() {

	}

	@Override
	public boolean needSave() {
		return true;
	}

	@Override
	public boolean doSaveBefore(PrimaryObjectEditorInput input,
			IProgressMonitor monitor, String operation) throws Exception {
		return true;
	}

	@Override
	public boolean doSaveAfter(PrimaryObjectEditorInput input,
			IProgressMonitor monitor, String operation) throws Exception {
		TaskForm taskform = (TaskForm) input.getData();
		Object choice = taskform.getValue("choice");
		Work work = taskform.getWork();
		if (Utils.isAdmit((String) choice)) {
			work.doSaveChangeType(taskform.getValue("type"), true);
		} else {
			work.doSaveChangeType(taskform.getValue("type"), false);
		}
		return true;
	}

}
